/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MODEL;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;


/**
 *
 * @author Irene & Morten
 */
public class Journalhandler extends Observable implements Observer, Serializable {

    private List<Journal> journals;
    private Journal activeJournal;

    public Journalhandler() {
        journals = new ArrayList<Journal>();
    }

    /*add journal to a list and adds an observer to j.
     * @param j is the list to be added
     */
    public void addJournalToList(Journal j) {
        journals.add(j);
        setChanged();
        notifyObservers();

        j.addObserver(this);
    }
/*Removed the active journal from the list
 * @param journal is the object to be removed from the list
 */
    public void removeJournalFromList(Object journal){
        journals.remove(journal);
         setChanged();
        notifyObservers();

        activeJournal.deleteObserver(this);
    }

    public List<Journal> getJournals(){
    return journals;
    }

    public Journal getActiveJournal(){
    return activeJournal;
    }

    public void setActiveJournal(Journal journal){
    activeJournal = journal;
        setChanged();
        notifyObservers();
    }

    public void update(Observable o, Object arg) {
        setChanged();
        notifyObservers();
    }

}
